{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "635f1bab-a491-4dac-acf6-9e94d118fbda",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "data = pd.read_csv('USA_Housing.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85b567d8-9345-44c9-926d-e444de934fbb",
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "from matplotlib import pyplot as plt\n",
    "fig = plt.figure(figsize=(10,10))\n",
    "fig1 = plt.subplot(2,3,1)\n",
    "plt.scatter(data.loc[:,'Avg. Area Income'], data.loc[:,'Price'])\n",
    "plt.title('Price VS Income')\n",
    "\n",
    "fig2 = plt.subplot(2,3,2)\n",
    "plt.scatter(data.loc[:,'Avg. Area House Age'], data.loc[:,'Price'])\n",
    "plt.title('Price VS House Age')\n",
    "\n",
    "fig3 = plt.subplot(2,3,3)\n",
    "plt.scatter(data.loc[:,'Avg. Area Number of Rooms'], data.loc[:,'Price'])\n",
    "plt.title('Price VS Number of Rooms')\n",
    "\n",
    "fig4 = plt.subplot(2,3,4)\n",
    "plt.scatter(data.loc[:,'Area Population'], data.loc[:,'Price'])\n",
    "plt.title('Price VS Area Population')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b53530b-e75e-4a6c-bc7b-cfbe947ff8c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "X =  data.loc[:,'Area Population']\n",
    "y = data.loc[:,'Price']\n",
    "X.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5eafdf69-2242-4281-8bd1-1d83498c2ac5",
   "metadata": {},
   "outputs": [],
   "source": [
    "y.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e6054eb-5b89-4e9c-8860-0f967c3b2799",
   "metadata": {},
   "outputs": [],
   "source": [
    "# set up the linear regression model\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "LR1 = LinearRegression()\n",
    "\n",
    "X = np.array(X).reshape(-1,1)\n",
    "print(X.shape)\n",
    "\n",
    "# train the model\n",
    "LR1.fit(X, y)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6835d69-66b3-4755-bdcc-5e4f44f26903",
   "metadata": {},
   "outputs": [],
   "source": [
    "# calculate the price vs area population\n",
    "y_predict_1 = LR1.predict(X)\n",
    "print(y_predict_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a7e5748-04a3-4e44-b2d6-4d7a0a5f3f07",
   "metadata": {},
   "outputs": [],
   "source": [
    "#evaluate the model\n",
    "from sklearn.metrics import mean_squared_error, r2_score\n",
    "mead_squared_error_1 = mean_squared_error(y, y_predict_1)\n",
    "r2_score_1 = r2_score(y, y_predict_1)\n",
    "print(mead_squared_error_1,r2_score_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bbcf2dc-cbc8-4c97-88b3-ae2db6fd7553",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig6 = plt.figure()\n",
    "plt.scatter(X,y)\n",
    "plt.plot(X,y_predict_1, 'r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "994d8fe4-5eb2-4e20-95fe-61aeb94db563",
   "metadata": {},
   "outputs": [],
   "source": [
    "#define X_multi\n",
    "X_multi = data.drop(['Price','Address'],axis=1)\n",
    "X_multi.head()\n",
    "X_multi\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47882626-a3ff-4046-a14d-510f48a102db",
   "metadata": {},
   "outputs": [],
   "source": [
    "LR_multi = LinearRegression()\n",
    "#train model\n",
    "LR_multi.fit(X_multi, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "277202a8-7b9f-4fa4-9c6d-23852bdb24a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_predict_multi = LR_multi.predict(X_multi)\n",
    "print(y_predict_multi)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c930bf94-07a7-4382-877c-be3499b80044",
   "metadata": {},
   "outputs": [],
   "source": [
    "mead_squared_error_multi = mean_squared_error(y, y_predict_multi)\n",
    "r2_score_multi  = r2_score(y, y_predict_multi)\n",
    "print(mead_squared_error_multi,r2_score_multi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e348a39-51e3-4a19-a414-465818952b1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig_multi = plt.figure()\n",
    "plt.scatter(y,y_predict_multi)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb894257-0ebc-46c4-98de-c1d48b7cdb00",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig_8 = plt.figure()\n",
    "plt.scatter(y,y_predict_1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2302e138-9f41-4ff0-892f-bb1007067c9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "XXX = [41545,5,6,4,70000]\n",
    "XXX = np.array(XXX)\n",
    "XXX = XXX.reshape(1,-1)\n",
    "\n",
    "print(XXX)\n",
    "yyy = LR_multi.predict(XXX)\n",
    "print('get',yyy)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7f6eebc-b6a4-4fff-a906-df40f7895ac4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db275224-fd36-4d6f-ad11-d0e6b1d1dc7b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe3ad2d5-e0fa-45de-9a72-fa7ab01bd302",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6266f5b5-0b87-4b26-8b50-b4ed47a1233f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc8c7bc6-9ec8-496c-a82e-621ecfef4fe5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca964e83-e787-4729-89ea-d4d425510802",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "316dacde-8438-409f-96b5-0a6f335f6af0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb5a35ed-fe02-40c3-8cb1-df112b94429d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61b68a0c-c8e2-4408-a1b2-05332b29a8a6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eccbec16-455c-4dfa-9910-6921e0364196",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9d5ddce-9bde-4692-90d0-43a418daf8b1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbb85b8d-1cb4-4c76-9117-ed12551a1348",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88cda1cc-0c72-4b79-8a02-1fe6d5abdacd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "772475f2-e34c-437d-88d8-93b2e6b31ce1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1f40407-897b-4215-9d74-7c2e2d6651fb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95ac8b31-dbab-4e65-ac84-52b9d8fec71b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4eff49b-2126-4156-a9fe-520c77c72a55",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e09210b-138c-4e9d-bd8b-e1cc74ed353c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "341339aa-84c5-4f5a-b78a-38308acc638b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25580516-0fc6-4620-9ade-a39a47f6ae44",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "818dd0c7-b660-4820-ab79-bcbb55014f38",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7bfdd43b-25f5-451a-b42f-37bfbc6bd90a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d625610-0d0f-4c10-9450-419fd03b501a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04ae4fe4-8196-404e-a02b-cb42ba4b2df0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0a1f2ce-2d11-46e9-949c-4fda816410bb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0376aa0-9080-4b53-9010-589b25f7e220",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b30ab7bb-e2f7-4b67-ad93-ad49422894ee",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c97d53d-8353-418c-970a-86c849fb8fc4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99cb454b-ea5a-4a31-8570-4c5eabc51fdd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2b16a66-e8ae-4e4a-ba90-66facbf6fdaa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce64d26f-97b5-47f5-be69-0d28a9292278",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78b62a64-e6b2-4454-8524-0f0381e6f677",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b29573ac-4d66-4bc9-8f7f-0cdd2015e699",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d31b29e-8080-446d-94a8-773b5fd43d2a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7139c36e-bb07-470c-995d-8f5ebb1190db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30665bc1-1174-416f-a5d1-b87fb6dd5e4f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb5c9a6f-d69d-4d3a-ab07-8d80994bb52e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e80dd68a-d1bd-48a0-bba6-3e31160d3985",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb29eaaa-175a-49be-a3d4-633adc467019",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecc7ae8b-2669-4e88-b158-5565be6db681",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81a26bce-11cf-49cf-81c0-780e72ca98ff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d10013a-2c4b-401a-880a-ab495b939614",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ad63e83-bcd5-4f67-b0af-43604aa01e0d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2095ddd8-24de-406e-8865-1135e0dad64d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6533978-5d4b-4aee-82fa-8f926751ca62",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea057644-a5cd-4240-8cfe-e587bd96f3dc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bacd984a-9c06-46d0-962f-b864b38d6d54",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f953fe42-6d84-4b44-ae74-78e440384025",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb14da99-d942-4841-9d09-7b6da2720ea5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6aefbfc0-932f-4e93-96ba-7025a98803fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b579eeb5-1d50-4215-a882-1acc4f94b3ab",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "801788ce-db17-43b4-812e-de66c916428d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
